(function($) {
    $.fn.extend({
        /**
         * 自定义ajax函数
         * 默认为表单提交，其他提交请传入url
         * @param {type} opeartion
         * @returns {undefined}
         */
        tyAjax: function(opeartion) {
            //设置默认变量
            var defaults = {isForm: true, url: null, type: 'post', data: null, dataType: 'JSON', async: true, isFormCheck:false,
                timeout: 10000, beforeSend:function(){loadding();}, beforeSubmit: function() {
                }, callBack: function() {
                }};
            //使用用户提供的选项设置默认值
            var opts = $.extend(defaults, opeartion);
            //判断是否表单提交
            if (opts.isForm) {
                //获取表单action
                opts.url = $(this).parents('form').attr('action');
                //序列化表单数据
                opts.data = $(this).parents('form').serialize();
            } else {
                //提交方式改为get
                opts.type = 'get';
            }
            //提交前表单验证
            if(opts.isFormCheck && !$(this).tyFormCheck()){
            	return false;
            }
            var retVal = opts.beforeSubmit();
            //提交前验证
            if (retVal !== undefined && !retVal) {
                return false;
            }
            //表单提交
            $.ajax({url: opts.url, type: opts.type, dataType: opts.dataType, data: opts.data, async: opts.async,
                timeout: opts.timeout,beforeSend:opts.beforeSend(), success: function(result) {
                	unloadding();
                    opts.callBack(result);
                }});
        }
    });
    
    if(jQuery.isFunction(jQuery.fn.placeholder)){
    	$('input, textarea').placeholder();
    }
})(jQuery);

/**
 * 获取和设置语言定义(区分大小写) 
 * @param string name 语言变量
 * @returns 语言值
 */
function L(name){
	var returnVal = langjs[name];
	
	if(typeof(returnVal) == "undefined"){
		return name;
	}
	
	return returnVal;
}

/**
 * 设置分页行数
 * @param {type} groupUrl 分组URL地址
 * @param {type} num 分页行数
 * @param {type} refreshUrl 刷新页面
 * @returns {undefined}
 */
function setListRow(groupUrl, num, refreshUrl) {
    $.get(groupUrl + '/Index/setListRows/num/' + num, function() {
        location.href = refreshUrl;
        alert(groupUrl + '/Index/setListRows/num/' + num + '<br>' + refreshUrl + '<br>');
    });
}

/**
 * checked全选与单选事件
 * @param {type} parent_selectors
 * @param {type} target_selectors
 * @returns {undefined}
 */
function checkAll(parent_selectors, target_selectors) {
    var parents = $(parent_selectors);
    var targets = $(target_selectors);
    parents.change(function() {
        targets.prop('checked', $(this).prop('checked'));
    });
    targets.change(function() {
        parents.prop('checked', targets.length === targets.filter(':checked').length);
    });
}

